<?php
/*
* 阿里云oss
*/

namespace library;

use OSS\OssClient;
use module\UploadApi;

class AliOss
{

    protected static $AccessKeyId;
    protected static $AccessKeySecret;
    protected static $Endpoint;
    protected static $Bucket;

    //init
    protected static function init()
    {
        $config = config('alioss.config');
        self::$AccessKeyId = $config['KeyId'];
        self::$AccessKeySecret = $config['KeySecret'];
        self::$Endpoint = $config['Endpoint'];
        self::$Bucket = $config['Bucket'];
    }

    //Get alioss client
    protected static function getClient()
    {
        self::init();
        $client = new OssClient(self::$AccessKeyId, self::$AccessKeySecret, self::$Endpoint);
      return $client;
    }

    //Upload project attach file
    public static function upload($file)
    {

        $data = $file->getInfo();
        $string = explode('.',$data['name']);
        //  $name=$string[0];
        //  $type = $string[1];
        //  $upload = new  UploadApi();
        //  $typeName = $upload->getSaveData($upload->getDataType($data['name']));

        $client = self::getClient();
        return $client->uploadFile(self::$Bucket, $data['name'], $data['tmp_name']);
    }




}
